package top.anka1.fxgui;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;

import javafx.scene.control.cell.PropertyValueFactory;
import top.anka1.ims.*;
import top.anka1.ims.RestaurantManagementSystem.Meal;

import java.util.ArrayList;
/**
 * Controller class for displaying meals in a table.
 * @author Anka
 */
public class DisplayMenuController {
    private RestaurantGUI restaurantGUI;
    @FXML
    private TableView<Meal> menuTable;
    @FXML
    private TableColumn<Meal, String> nameColumn;
    @FXML
    private TableColumn<Meal, String> ingredientColumn;

    public void setData(RestaurantGUI restaurantGUI) {
        this.restaurantGUI = restaurantGUI;
        nameColumn.setCellValueFactory(new PropertyValueFactory<>("name"));
        nameColumn.setStyle("-fx-alignment: CENTER;");
        ingredientColumn.setCellValueFactory(new PropertyValueFactory<>("ingredientsString"));
        ingredientColumn.setStyle("-fx-alignment: CENTER;");

        ArrayList<Meal> menuList = restaurantGUI.getRestaurantService().getMenu();
        ObservableList<Meal> meals = FXCollections.observableArrayList(menuList);
        menuTable.setItems(meals);
    }
}
